// 检查手机格式
function Check_Phone(id, st) {
    HideTips();
    var phone = $("#" + id).val().trim();
    var holderCont = $("#" + id).attr("placeholder");
    if (phone == "" || phone == holderCont) {
        ShowTips("请输入手机号", st);
        return false;
    } else if (!(/^\s*1\d{10}\s*$/gi).test(phone)) {
        ShowTips("手机号格式不正确", st);
        return false;
    }
    return true;
}

// 检查短信验证码格式
function Check_SmsCode(id, st) {
    HideTips();
    var phoneCode = $("#" + id).val().trim();
    var holderCont = $("#" + id).attr("placeholder");
    if (phoneCode == "" || phoneCode == holderCont) {
        ShowTips("请输入您的短信验证码!", st);
        return false;
    } else if (!(/^\d{6}$/gi).test(phoneCode)) {
        ShowTips("您输入的短信验证码有误，请重新输入!", st);
        return false;
    }
    return true;
}

// 检查邮箱格式
function Check_Email(id, st) {
    HideTips();
    var Email = $("#" + id).val().trim();
    var holderCont = $("#" + id).attr("placeholder");
    if (Email == "" || Email == holderCont) {
        ShowTips("请输入您的邮箱账号", st);
        return false;
    } else if (!/^[\w-]+(\.[\w-]+)*@[\w-]+(\.(\w)+)*(\.(\w){2,3})$/.test(Email)) {
        ShowTips("请输入有效的邮箱账号", st);
        return false;
    }
    return true;
}

// 检查账号格式
function Check_Account(id, st) {
    HideTips();
    var Account = $("#" + id).val().trim();
    var holderCont = $("#" + id).attr("placeholder");
    if (Account == "" || Account == holderCont) {
        ShowTips("请输入您的手机号码", st);
        return false;
    } else if (!(/^\s*1\d{10}\s*$/gi).test(Account)) {
        ShowTips("请输入有效的手机号码", st);
        return false;
    }
    return true;
}

// 检查密码格式
function Check_Password(id, st) {
    HideTips();
    var Password = $("#" + id).val().trim();
    var holderCont = $("#" + id).attr("placeholder");
    if (Password == "" || Password == holderCont) {
        ShowTips("请输入密码!", st);
        return false;
    } else if (Password.length < 6) {
        ShowTips("密码长度不小于6位", st);
        return false;
    }
    return true;
}

// 检查图形验证码
function Check_Code(id, st) {
    HideTips();
    var codeInput = $("#" + id);
    var codeBox = codeInput.parents(".verify-box");
    var ValidCode = codeInput.val().trim();
    var holderCont = codeInput.attr("placeholder");
    if (codeBox.css("display") == "block") {
        if (ValidCode == "" || ValidCode == holderCont) {
            ShowTips("请输入图形验证码", st);
            return false;
        } else if (ValidCode.length != 4) {
            ShowTips("请输入正确的图形验证码", st);
            return false;
        }
        return ValidCode;
    } else {
        return "";
    }
}

// 提示文字
function ShowTips(nr, st) {
    $(".tips").html("");
    $(st).find(".tips").html(nr);
}
// 清除提示
function HideTips() {
    $(".tips").html("");
}

// 刷新图形验证码
function RefreshImage(valImageId) {
    var objImage = $("#" + valImageId);
    if (objImage == undefined) {
        return;
    }
    var imgUrl = objImage.attr("src").split("?")[0];
    var now = new Date();
    objImage.attr('src', imgUrl + '?' + now.toUTCString());
}

// 刷新图形验证码
function RefreshImage2(valImageId, valPhoneId, type) {//type:phone||email
    var valPhoneId = valPhoneId || "UserPhone";
    var type = type || "phone";
    var phone = "";
    if (type == "phone") {
        if (!Check_Phone(valPhoneId, ".tel-box")) return false;
        phone = $("#" + valPhoneId).val().trim();
    }
    if (type == "email") {
        if (!Check_Email(valPhoneId, ".email-box")) return false;
        phone = $("#" + valPhoneId).val().trim();
    }
    $.ajax({
        type: "post",
        url: "/huactrler/geetestcaptchaV1",
        dataType: "json",
        data: {
            platform: 'web',
            mobile: phone
        },
        success: function (res) {
            $("#" + valImageId).attr("src", res.Datas.ImgData);
        }
    })
}

//非支持placeholder浏览器处理
if (document.getElementById('form1')) {
    var oForm1 = document.getElementById('form1');
    var oForm1Inputs = oForm1.getElementsByTagName('input');
    for (var i = 0; i < oForm1Inputs.length; i++) {
        placeHolder(oForm1Inputs[i], false);
    }
    var oForm1Textarea = oForm1.getElementsByTagName('textarea')[0];
    if (oForm1Textarea != null && oForm1Textarea != undefined) {
        placeHolder(oForm1Textarea, true);
    }
}

function placeHolder(obj, span) {
    if (!obj.getAttribute('placeholder')) return;
    var imitateMode = span === true ? true : false;
    var supportPlaceholder = 'placeholder' in document.createElement('input');
    if (!supportPlaceholder) {
        var defaultValue = obj.getAttribute('placeholder');
        $(".cover-pwd").show();
        $(".cover-pwd").click(function () {     // 点击密码输入框，隐藏输入框覆盖层
            var _this = $(this);
            var _input = $(this).siblings("input");
            var value = _input.val();
            _input.val('').focus().val(value);  // 重新赋值使光标在输入框最后
            _this.hide();
        })
        $(".cover-pwd").siblings("input").focus(function () {     // 点击输入框覆盖层获得焦点，或tab键获得焦点
            var _input = $(".cover-pwd").siblings("input");
            var value = _input.val();
            _input.val(value);      // 重新赋值使光标在输入框最后
            $(".cover-pwd").hide();
        })
        $(".cover-pwd").siblings("input").blur(function () {
            var _this = $(".cover-pwd");
            var len = $(this).val().length;
            var divcont = "";
            var divcolor = "#B4BABF";
            if (len != 0 && $(this).val() != "请输入密码") {
                divcolor = "#232628";
                for (var i = 0; i < len; i++) {
                    divcont = divcont + "●";
                }
            } else {
                divcolor = "#B4BABF";
                divcont = "请输入密码"
            }
            _this.css("color", divcolor)
            _this.html(divcont);
            _this.show();
        })
        if (!imitateMode) {
            obj.onfocus = function () {
                (obj.value == defaultValue) && (obj.value = '');
                obj.style.color = '';
            }
            obj.onblur = function () {
                if (obj.value == defaultValue) {
                    obj.style.color = '';
                } else if (obj.value == '') {
                    obj.value = defaultValue;
                    obj.style.color = '#B4BABF';
                }
            }
            obj.onblur();
        } else {
            var placeHolderCont = document.createTextNode(defaultValue);
            var oWrapper = document.createElement('span');
            oWrapper.style.cssText = 'position:absolute; color:#B4BABF; display:inline-block; overflow:hidden;';
            oWrapper.className = 'wrap-placeholder';
            oWrapper.style.fontFamily = getStyle(obj, 'fontFamily');
            oWrapper.style.fontSize = getStyle(obj, 'fontSize');
            oWrapper.style.marginLeft = parseInt(getStyle(obj, 'marginLeft')) ? parseInt(getStyle(obj, 'marginLeft')) + 3 + 'px' : 3 + 'px';
            oWrapper.style.marginTop = parseInt(getStyle(obj, 'marginTop')) ? getStyle(obj, 'marginTop') : 1 + 'px';
            oWrapper.style.paddingLeft = getStyle(obj, 'paddingLeft');
            oWrapper.style.width = obj.offsetWidth - parseInt(getStyle(obj, 'marginLeft')) + 'px';
            oWrapper.style.height = obj.offsetHeight + 'px';
            oWrapper.style.lineHeight = obj.nodeName.toLowerCase() == 'textarea' ? '' : obj.offsetHeight + 'px';
            oWrapper.appendChild(placeHolderCont);
            obj.parentNode.insertBefore(oWrapper, obj);
            oWrapper.onclick = function () {
                obj.focus();
            }

            if (typeof (obj.oninput) == 'object') {
                obj.addEventListener("input", changeHandler, false);
            } else {
                obj.onpropertychange = changeHandler;
            }

            function changeHandler() {
                oWrapper.style.display = obj.value != '' ? 'none' : 'inline-block';
            }

            function getStyle(obj, styleName) {
                var oStyle = null;
                if (obj.currentStyle)
                    oStyle = obj.currentStyle[styleName];
                else if (window.getComputedStyle)
                    oStyle = window.getComputedStyle(obj, null)[styleName];
                return oStyle;
            }
        }
    } else {
        // 当支持placeholder属性时
        var _inputPwd = $(".cover-pwd").siblings("input");
        var placeholederVal = $(".cover-pwd").html();
        if (_inputPwd.attr("autocomplete") == "off") {
            // 用户保存当前域名的账号密码到浏览器后，在登录页以外的操作表单遇到密码输入框会自动填充账号及密码的优化处理，对应input输入框autocomplete属性设置为off
            _inputPwd.attr("type", "text");
            _inputPwd.attr("placeholder", placeholederVal);
            _inputPwd.focus(function () {
                $(this).attr("type", "password");
            })
        } else {
            // 登录相关表单,对应input输入框autocomplete属性默认开启
            _inputPwd.attr("placeholder", placeholederVal);
        }
    }
}

//非支持placeholder浏览器处理end